/*
 * ProtocolData.h
 *
 *  Created on: Sep 7, 2017
 */

#ifndef _UART_PROTOCOL_DATA_H_
#define _UART_PROTOCOL_DATA_H_

#include <string>
#include "CommDef.h"

/******************** CmdID ***********************/
enum class DataTypeCode : uint8_t {
    Vehicle = 0x10,               // 车辆数据
    TempPressure = 0x11,          // 温度压力数据
    FaultIndicator = 0x30,        // 故障指示灯数据
    WarningMessage = 0x31,        // 故障提示信息
    FuelRange = 0x50,             // 油量续航数据
    TotalMileage = 0x51,          // 总里程数据
    TripMileage = 0x52,           // 小计里程数据
    FuelConsump = 0x53,           // 油耗历史数据
    TruckInfo = 0x70,             // 卡车信息
    BodyInfo = 0x71,              // 车身信息
    TrailerInfo = 0x73,           // 拖车信息
    OffroadInfo = 0x74,           // 越野信息
    TirePressure = 0x90,          // 胎压数据
    CruiseControl = 0x91,         // 巡航数据
    SettingInfo = 0xA0,           // 设置信息
    SetOperation = 0xA1,          // 设置操作
    ControlCommand = 0xA2,        // 控制命令
    ControlKey = 0xA3,            // 控制按键
    RemoteKey = 0xA4,             // 遥控钥匙管理
    DateTime = 0xA5,              // 日期时间
    Request = 0xC0,               // 请求数据
    Upgrade_SLAVE = 0x69,         // 软件升级 (解码盒发送)
    Update_HOST = 0xD9            // 主机发送
};
/**************************************************/
typedef union {
    uint8_t byte;  // 整个字节
    struct {
        unsigned bit0 :1;  // 第0位
        unsigned bit1 :1;  // 第1位
        unsigned bit2 :1;  // 第2位
        unsigned bit3 :1;  // 第3位
        unsigned bit4 :1;  // 第4位
        unsigned bit5 :1;  // 第5位
        unsigned bit6 :1;  // 第6位
        unsigned bit7 :1;  // 第7位
    } bits;  // 位字段
} ByteBits;

// 重载 == 运算符
inline bool operator==(const ByteBits& lhs, const ByteBits& rhs) {
    return lhs.byte == rhs.byte;
}

// 重载 != 运算符
inline bool operator!=(const ByteBits& lhs, const ByteBits& rhs) {
    return !(lhs == rhs);
}
/******************** 错误码 Error code ***********************/
#define ERROR_CODE	0x01	//数据请求超时（5秒）
/**************************************************/
typedef enum{
	KEY_NULL,
	KEY_UP,		//上按键
	KEY_DOWN,		//下
	KEY_LEFT,		//左
	KEY_RIGHT,		//右
	KEY_OK,		//确认
//		KEY_cruisePLUS,	//巡航设置加
//		KEY_cruiseMINUS,//巡航设置减
//		KEY_RES,		//RES巡航复位
//		KEY_CNCL,	//CNCL巡航取消
//		KEY_ON,		//巡航开
//		KEY_PFF,	//巡航关
}key_operation_e;

typedef enum{
	KEY_O,	//松开
	KEY_1,	//短按
	KEY_2	//长按
}key_status;

typedef struct {
	ByteBits ACC;
	ByteBits door;
	uint8_t gear;
	uint8_t gearRank;
	bool ShiftLever;	//换挡杆
	uint16_t rotation_; 		//发动机转速
	uint16_t speed_; 	//瞬时车速

	int CoolantTemp;	//冷却液温度
	int TransmissionTemp;	//变速箱温度
	int OutdoorTemp; 		//室外温度
	int EngineOilTemp; 		//机油温度
	uint16_t OilPressure;		//机油压力
	uint8_t Turbinepressure;	//涡轮压力

	ByteBits pilotLamp0;
	ByteBits pilotLamp1;
	ByteBits pilotLamp2;

	ByteBits prompt0;
	ByteBits prompt1;
	ByteBits prompt2;
	bool TireMonitoring;	//胎压监测
	bool TrailerBrake;		//拖车刹车
	uint8_t countdownACC;	//ACC自动关闭倒计时
	uint8_t countdownShut;	//发动机自动熄火倒计时
	uint8_t CalibrateGyro;		//校准陀螺仪
	uint8_t CalibrateCompass;	//校准指南针

	uint16_t RangeEndurance; 	//续航里程
	uint8_t Oil_percentage;		//剩余油量百分比

	int odo;	//总里程

	int SubtotalMileage1;		//小计里程1
	uint16_t AverageFueL1; 		//平均油耗1
	int TravelTime1; 			//行驶时间1
	uint16_t AverageVelocity1;		//平均速度1
	int SubtotalMileage2;		//小计里程2
	uint16_t AverageFueL2; 		//平均油耗2
	int TravelTime2; 			//行驶时间2
	uint16_t AverageVelocity2;		//平均速度2

	uint16_t AverageFuel; 		//平均油耗
	uint16_t FuelHistory1;
	uint16_t FuelHistory2;
	uint16_t FuelHistory3;
	uint16_t FuelHistory4;
	uint16_t FuelHistory5;
	uint16_t FuelHistory6;

	uint8_t oilLife; 			//机油寿命
	uint16_t EngineHours;		//发动机时间
	uint16_t EngineIdleHours;	//发动机空闲时间
	uint8_t MyKeys;		//遥控钥匙数量
	uint8_t AdminKeys;	//管理遥控钥匙数量

	char VIN[18];		//VIN车身码

	uint8_t TrailerAngle1;	//拖车角度1
	uint8_t TrailerAngle2;	//拖车角度2
	bool TrailerDirection1;	//方向标识
	bool TrailerDirection2;
	uint8_t Gain;
	uint16_t TrailerDistance;		//拖车行驶距离
	ByteBits TrailerInfo;
	uint8_t TrailerEffort;		//拖车刹车力度
	uint8_t TrailerType;		//拖车类型

	uint8_t mode_4WD;
	uint8_t status_4WD;
	uint8_t FLWheelPower;
	uint8_t FRWheelPower;
	uint8_t RLWheelPower;
	uint8_t RRWheelPower;

	uint8_t FRpitchAngle;	//前后俯仰角
	bool ElevationAngle;	//俯仰角方向
	uint8_t LRrollAngle;	//左右侧顷
	bool RollAngle;			//侧倾角
	uint8_t compass;	//指南针

	uint16_t FL_TP;		//前左轮胎压
	uint16_t FR_TP;		//前右轮胎压
	uint16_t RL_TP;		//后左轮胎压
	uint16_t RR_TP;		//后右轮胎压

	bool CruiseBool;
	uint8_t CruiseSpeed; 	//定速巡航速度


	ByteBits SetInfo0;
	uint8_t AutolampDelay;	//自动大灯延时
	bool DaytimeLight;		//日间行车灯

	ByteBits SetInfo2;
	uint8_t PowerRunningBoards;	//电动踏板

	ByteBits SetInfo3;
	uint8_t RemoteStart;	//远程启动-持续时间

	ByteBits SetInfo4;
	uint8_t language;
	uint8_t Backlight;		//背光亮度




	key_status pre_status;		//上一次按键状态
	key_status status;			//按键状态
	key_operation_e operation;	//按键操作

	uint8_t Year;
	uint8_t Month;
	uint8_t Day;
	uint8_t Hour;
	uint8_t Minute;
	uint8_t Second;

	uint8_t KeyCtrl;	//钥匙控制

} SProtocolData;

#endif /* _UART_PROTOCOL_DATA_H_ */
